package com.learn.notice.service;

import com.learn.dao.NoticeDao;
import com.learn.model.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeDao noticeDao;
    
    @Override
    public String addNotice(Notice notice) {
        if (StringUtils.isEmpty(notice.getTitle())) {
            return "通知标题不能为空";
        }
        
        notice.setEntryDate(LocalDateTime.now()).setDbSource("learn_cloud_9001");
        noticeDao.save(notice);
        return "添加成功";
    }
    
    @Override
    public List<Notice> listNoticeByType(Notice.NoticeType noticeType) {
        return noticeDao.findByNoticeType(noticeType);
    }
    
    @Override
    public List<Notice> findAllNotice() {
        return noticeDao.findAll();
    }
}
